using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using LeisureCenter.Api;
using LeisureCenter.Forms;

namespace LeisureCenter.Core
{
    public class UIManager : ILeisureCenterUIManager
    {
        #region ILeisureCenterUIManager Membres

        public Form CreateAlphaBackgroundForm()
        {
            return CreateAlphaBackgroundForm(Color.White);
        }

        public Form CreateAlphaBackgroundForm(Color color, double opacity)
        {
            Form form = new Form();
            form.Opacity = opacity;
            form.BackColor = color;
            form.FormBorderStyle = FormBorderStyle.None;
            form.WindowState = FormWindowState.Maximized;
            form.TopMost = true;
            form.Click += new EventHandler(HandleAlphaBackgroundFormClick);
#if DEBUG
            form.Shown += new EventHandler(HandleAlphaBackgroundFormClick);
#endif
            return form;
        }

        void HandleAlphaBackgroundFormClick(object sender, EventArgs e)
        {
            ((Form)sender).Hide();
        }

        public Form CreateAlphaBackgroundForm(Color color)
        {
            return CreateAlphaBackgroundForm(color, 0.5);
        }

        public void ShowCustomScreen(Control customScreen, bool showSubmenu)
        {
            if (customScreen == null)
                return;

            Program.LeisureCenterInstance.MainForm.pnlBrowserAndInfo.Visible = false;
            customScreen.Parent = Program.LeisureCenterInstance.MainForm.pnlCustomScreens;
            if (showSubmenu)
            {
                Program.LeisureCenterInstance.MainForm.pnlCustomScreens.Width = Program.LeisureCenterInstance.MainForm.pnlBrowserAndInfo.Width - Program.LeisureCenterInstance.MainForm.pnlSubmenu.Width;
                Program.LeisureCenterInstance.MainForm.SlidePosition = SlidePosition.Submenu;
            }
            else
            {
                Program.LeisureCenterInstance.MainForm.pnlCustomScreens.Width = Program.LeisureCenterInstance.MainForm.pnlBrowserAndInfo.Width;
                Program.LeisureCenterInstance.MainForm.SlidePosition = SlidePosition.CustomScreen;
            }
            Program.LeisureCenterInstance.MainForm.pnlCustomScreens.Visible = true;
        }

        public DialogResult MessageBox(string message, string iconName, MessageBoxButtons buttons, Color background)
        {
            Form backgroundForm = CreateAlphaBackgroundForm(background);
            using (backgroundForm)
            {
                backgroundForm.Show();
                MessageBoxForm messageBox = new MessageBoxForm();
                using (messageBox)
                {
                    messageBox.lblMessage.Text = message;
                    messageBox.lblMessage.ImageList = Program.LeisureCenterInstance.IconsManager[IconSize.s96x96];
                    messageBox.lblMessage.ImageKey = iconName;
                    return messageBox.ShowDialog();
                }
            }
        }

        public bool ListDialog(IEnumerable<string> items, bool showCancel, ref int index, Color alphaBackgroundColor)
        {
            return LeisureCenter.Forms.ListDialog.Execute(items, showCancel, ref index, alphaBackgroundColor);
        }

        #endregion
    }
}
